<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-CN" lang="zh-CN">
<head>
<title>添加用户</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<meta name="copyright" content="" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="robots" content="all" />
<meta name="generator" content="EditPlus" />

<style type="text/css" media="screen">
   @import url(../css/mngMain.css);
</style>

<script type="text/javascript" src="../js/jquery.js"></script>

<script type="text/javascript">
     var ret_global;
     function checkUsername(){
         var usernameval=$('#userNameId').attr('value');  	 
	  	 $("#userNameId").click( function(){	  	
	  	 	  if((usernameval==undefined)||(usernameval==null)){
	  	 	  	 $("#username_message").css('color','gray');	  	 	  	
	  	 	     $("#username_message").html("[请输入用户名.]");
	  	 	  }
	  	 });
	  	
	  	 $("#userNameId").blur( function(){  	 	  
	  	 	  validateUsername();	  	 	   	 	
	  	 });	 	 	          
     }
     
        
     function validateUsername(){              
               $("#username_message").html("");             
            	var userName = $("#userNameId").attr("value");
           		$("#username_message").css("text-align","left");
                $("#username_message").css("color","red");  
           		if((userName==undefined)||(userName==null)){
           			$('#username_message').html("(用户名不能为空.)");
           			 ret_global=false;
           		}else if(userName.length>13){
				    $("#username_message").html("(用户名长度过大.)");
				     ret_global=false;
			    }          		
           		else{          		    
           			$.post("../admin/isUserExist.do",{userName:userName},
           						function(getText){
           			//	  var retInfo=$("user",getXml);            	
				    //    var retState=$("result",retInfo).text();	
				        retState=getText; 				       	        
				        if ( retState == "fail" )
				        {
				        	var info = "数据载入失败";		        
					        $("#username_message").html(info);		
					        ret_global=false;        
				        	return false;
				        }else {
				        	if(retState=="noReg"){
	  	 	  					 $("#username_message").css('color','green');
				        		 $("#username_message").html("(用户名可用..)");	
				        	}else if(retState=="isReg"){				        	 
				        		$("#username_message").html("(用户名被占用..)");	
                   				ret_global=false;               
				        	}
				        }			        
			        
           			});
           		}	   
     }
    
    function checkNickName(){
         var nickname=$('#nickname_jq').attr('value');  	 
	  	 $("#nickname_jq").click( function(){	  	
	  	 	  if((nickname==undefined)||(nickname==null)){
	  	 	  	 $("#nickname_message").css('color','gray');	  	 	  	
	  	 	     $("#nickname_message").html("[请输入用户昵称.]");
	  	 	  }
	  	 });
	  	
	  	 $("#nickname_jq").blur( function(){  	 	  
	  	 	  validateNickName();	  	 	   	 	
	  	 });	 	 	          
    } 
    
    function validateNickName(){
          $("#nickname_message").html("");             
          var nickname=$('#nickname_jq').attr('value');  	
          $("#nickname_message").css("text-align","left");
          $("#nickname_message").css("color","red");  
          if((nickname==undefined)||(nickname==null)){
              $('#nickname_message').html("(用户昵称不能为空.)");
           	  ret_global=false;
          }
    } 
     
    function checkPassword(){
         var passwordval=$('#password_jq').attr('value');  	 
	  	 $("#password_jq").click( function(){	  	
	  	 	  if((passwordval==undefined)||(passwordval==null)){
	  	 	  	 $("#password_message").css('color','gray');	  	 	  	
	  	 	     $("#password_message").html("[请给自己设一个密码.]");
	  	 	  }
	  	 });
	  	
	  	 $("#password_jq").blur( function(){  	 	  
	  	 	 validatePassword();	 	
	  	 });	 	 	               
     }
     
     function validatePassword(){
                var password=$("#password_jq").attr("value");
                $("#password_message").css("text-align","left");
                $("#password_message").css("color","red");  
                if(password==null){
                   $("#password_message").html("(密码不能为空)");  
                   ret_global=false;                
                }
                else if(password.length<6){
                   $("#password_message").html("(密码需大于6个字符)");  
                   ret_global=false;                                                                               
                }
                else if(password.length>15){
                   $("#password_message").html("(密码需小于15个字符)");   
                   ret_global=false;               
                }
                else{
                   $("#password_message").html("");      
                }                                   
     }
     
     function checkPassword2(){
             var password2val=$('#password2_jq').attr('value');  	 
		  	 $("#password2_jq").click( function(){	  	
		  	 	  if((password2val==undefined)||(password2val==null)){
		  	 	  	 $("#password2_message").css('color','gray');	  	 	  	
		  	 	     $("#password2_message").html("[请再次输入上面的密码.]");
		  	 	  }
		  	 });
		  	
		  	 $("#password2_jq").blur( function(){  	 	  
		  	 	 validatePassword2();	 	
		  	 });	 	 	                       
     }
     
     function validatePassword2(){
                var password2=$("#password2_jq").attr("value");
                $("#password2_message").css("text-align","left");
                $("#password2_message").css("color","red");  
                if(password2!=$("#password_jq").attr("value")){
                   $("#password2_message").html("(两次输入的密码不一致)");  
                   ret_global=false;                
                }                 
                else{
                   $("#password2_message").html("");      
                }                                    
     }
     
     $(function(){
          $('#userNameId').attr('value',"");
          $('#password_jq').attr('value',"");
          $('#password2_jq').attr('value',"");  	
          $('#contact_person_jq').attr('value',"");
          $('#telphone_jq').attr('value',""); 
          $('#email_jq').attr('value',"");  
                             
          $("#unit_tr").hide();  
          $("#innercat_table").hide();
          $("#outercat_table").hide(); 
          
          ret_global = true;
          checkUsername();
          checkNickName();
          checkPassword();    
          checkPassword2();  
          
          $("#usertype_jq").change( function(){	  		         	   
	     	   if("2" == $("#usertype_jq").attr("value")){
	     	         $("#unit_tr").show();
	     	         $("#innercat_table").hide();
	     	         $("#outercat_table").show();
	     	   }
	     	   else if("1" == $("#usertype_jq").attr("value")){
	     	   	     $("#unit_tr").hide();
	     	   	     $("#innercat_table").show();
	     	   	     $("#outercat_table").hide();   
	     	   }else{
	     	         $("#unit_tr").hide();
	     	         $("#innercat_table").hide();
          			 $("#outercat_table").hide();  
	     	   }	        
	      });	
	      
	            
         	      	      
          $("#add_btn").click( function(){  
                  ret_global = true;
                  validateUsername();
                  validateNickName();
		          validatePassword();    
		          validatePassword2();  
		          if("-1" == $("#usertype_jq").attr("value")){
		                 alert("请选择用户身份");
			     	     ret_global = false;
			      }
			      if("-1" == $("#unit_jq").attr("value")){
			          if("2" == $("#usertype_jq").attr("value")){
		                 alert("外部用户请选择单位");
			     	     ret_global = false;
			     	  }
			      }     			    
                  if (ret_global == true) {                                        
                	$("#createUserForm").submit();
                  }
                  return false;                     
          });
     });
</script>
</head>



<body>
<div class="controlBox">
	<%@include file="../admin_top.jsp" %>
	<div class="mngMain">
		<div class="mngLeft">
			<%@include file="../admin_menu.jsp" %>
		</div>
		<div class="mngRight">
			<div class="mngRightContainer">
				<div class="mngRightContainerT">添加用户</div>
                <html:form action="createUser.do" styleId="createUserForm">
					<div class="mngRightContainerM">
						<table class="addUser">
							<tr>
								<th>用户名：</th>
							  	<td><html:text property="username" styleId="userNameId"/><span>*</span><span id="username_message"></span></td>
							</tr>
							<tr>
								<th>用户昵称：</th>
							  	<td><html:text property="nickname" styleId="nickname_jq"/><span>*</span><span id="nickname_message"></span></td>
							</tr>
							<tr>
								<th>姓 别：</th>
								<td><html:text  property="sex"/></td>
							</tr>
							<tr>
								<th>密 码：</th>
								<td><html:password property="pwd" styleId="password_jq"/><span>*</span><span id="password_message"></span></td>
							</tr>
							<tr>
								<th>确认密码：</th>
								<td><html:password property="pwdck" styleId="password2_jq"/><span>*</span><span id="password2_message"></span></td>
							</tr>
							<tr>
								<th>联系人：</th>
								<td><html:text styleId="contact_person_jq" property="contactPerson"/></td>
							</tr>
							<tr>
								<th>联系电话：</th>
								<td><html:text styleId="telphone_jq" property="telphone"/></td>
							</tr>
							<tr>
								<th>电子邮件：</th>
								<td><html:text styleId="email_jq" property="email"/>				
								 <input type="hidden" id="usertype_jq" name="type" value="1"/>
								</td>
							</tr>
							<tr>
								<th>传 真：</th>
								<td><html:text  property="fax"/></td>
							</tr>
							<tr>
								<th>MSN：</th>
								<td><html:text  property="msn"/></td>
							</tr>
							<tr>
								<th>QQ：</th>
								<td><html:text  property="qq"/></td>
							</tr>
							<tr>
								<th>公司名称：</th>
								<td><html:text  property="companyName"/></td>
							</tr>
							<tr>
								<th>公司地址：</th>
								<td><html:text  property="companyAddress"/></td>
							</tr>
							
							
							<tr>
								<td></td>
								<td>
									<a href="#" id="add_btn"><img src="../img/yesBtn.gif" /></a>
								</td>
							</tr>
						</table>
					</div>
				</html:form>				
			</div>
		</div>
	</div>
	<div class="mngBottom">
		<div class="mngLine"></div>
	</div>
</div>
</body>
</html>